<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>BMI计算</h1>
		<div id="">
			体重(kg):<input type="text" id="input1"/><br />
			身高(m):<input type="text" id="input2"/><br />
			结果:<input type="text" id="input3"/><br />
			<button type="button" onclick="cal()">计算</button>
		</div>
		
		<script type="text/javascript">
			function cal()
			{
				//1.得到身高体重
				//查找网页元素
				var input1=document.getElementById("input1");
				var input2=document.getElementById("input2");
				//得到用户输入的数值
				var tizhong = input1.value;
				var shengao = input2.value; 
				//2.放入结果
				var jieguo=tizhong/(shengao*shengao);
				//查找input3元素
				var input3 = document.getElementById("input3");
				//设置它的value属性
				input3.value=jieguo;
				//判断
				if(jieguo<=18.4){
					alert("偏瘦")
				}else if(18.5<=jieguo&&jieguo>=23.9){
					alert("正常")
				}else if(24<=jieguo&&jieguo>=27.9){
					alert("过重")
				}else{
					alert("肥胖")
				}
			}
		</script>
	</body>
</html>
